<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 50px;
            margin: 10px auto;
        }

        input {
            padding: 2px 20px;
        }
    </style>
</head>

<body>
    <div>
        <input type="button" value="0">
    </div>
</body>
<script>
    // 获取input  标签
    var input = document.getElementsByTagName('input')[0]
    // console.log(input);

    function sum() {
        // 获取，input里面的value
        var sum = parseInt(input.value)
        var i = 1
        return (sum += i)  //此处需要设置返回值，onclick事件中alert和value需要用到该返回值
    }

    input.onclick = function () {
        console.log(input.value); // 此时value为初始字符，需要转换为数字型
        alert(sum())
        this.value = sum()
    }
</script>

</html>